package com.aps.server.utils.converter;


import com.aps.common.model.standardAps.StandardApsEquipment;
import com.aps.server.entity.BasicEquip;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author jsy
 * @description:机器转换器
 * @date 2025/9/23 13:52
 */
public class EquipmentConverter {
    /**
     * @description: List<BasicEquip> 转 List<StandardApsEquipment>
     * @author: jsy
     * @time: 2025/9/23 13:51
     */
    public static List<StandardApsEquipment> convert(List<BasicEquip> basicEquipList) {
        if (basicEquipList == null) {
            return Collections.emptyList();
        }
        return basicEquipList.stream()
                .map(EquipmentConverter::convertSingle) // 调用单对象转换方法
                .collect(Collectors.toList());
    }

    /**
     * @description: 单对象转换：处理单个BasicEquip到StandardApsEquipment的映射
     * @author: jsy
     * @time: 2025/9/23 13:51
     */
    public static StandardApsEquipment convertSingle(BasicEquip basicEquip) {
        // 处理输入对象为null的情况
        if (basicEquip == null) {
            return null;
        }

        StandardApsEquipment apsEquipment = new StandardApsEquipment();
        // 字段映射：Long类型id转为String
        apsEquipment.setId(basicEquip.getId() != null ? String.valueOf(basicEquip.getId()) : null);
        // 设备名称直接映射
        apsEquipment.setEquipmentName(basicEquip.getEquipName());
        // 设备类型直接映射
        apsEquipment.setEquipmentType(basicEquip.getEquipType());
        // 此处使用equipCode作为设备唯一序列号（可根据实际业务调整）
        apsEquipment.setSerialNumber(basicEquip.getEquipCode());

        return apsEquipment;
    }
}
